<?php

class ImportardadosController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }
    
    public function uploadAction(){
        
        $this->_helper->layout->disableLayout();

        $options = array('ignoreNoFile' => TRUE);
        $upload = new Zend_File_Transfer();
        $upload->setOptions($options);
        $files = $upload->getFileInfo();
        $upload->setDestination("files");       

        foreach ($files as $field => $contents) {
            if (!strlen($contents["name"])) {  //Evita upload de arquivos sem nome
                continue;
            }

            if ($upload->receive($field)) {
                $extension = array_pop(explode(".", $contents["name"]));

                if (array_search($extension, $files)) {
                    $thumbModel->getThumbnail('/files/' . $contents['name'], '/files/' . $contents['name'] . "_thumb.png", 80);
                    $thumbnail = '/files/' . $contents["name"] . '_thumb.png';
                } else {
                    $thumbnail = '/imagens/File-Complete.png';
                }

                echo '[
                        {
                          "name":"' . $contents["name"] . '",
                          "size":' . $contents["size"] . ',
                          "url":"/files/' . $contents["name"] . '",
                          "thumbnail_url":"' . $thumbnail . '",
                          "delete_url":"\/\/example.org\/upload-handler?file=picture1.jpg",
                          "delete_type":"DELETE"
                        }
                      ]';
            }
        }    
      }    
}
